#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: henry_oulen
@file: makefile.py
@time: 2023/8/26 11:11
@desc: 
"""
import base64
import os
def pic2py(picture_names, py_name):
    write_data = []
    for picture_name in picture_names:
        filename = picture_name.replace('.', '_')
        with open("%s" % picture_name, 'rb') as r:
            b64str = base64.b64encode(r.read())
        # 注意这边 b64str 一定要加上.decode()
        write_data.append('%s = "%s"\n' % (filename, b64str.decode()))

    with open(f'{py_name}.py',
              'w+') as f:  # 当前文件所在路径中的Image/<py_name>.py 文件   你也可以自己修改这个路径到桌面等其他位置C:\Users\admin\Desktop\aaa.py
        for data in write_data:
            f.write(data)


# 需要转码的图片：

os.chdir('./Image')  # 变更路径到当前文件中的Image文件夹
pics = ['background.jpg']  # 将你的图片都输入进去
pic2py(pics, 'image')